package com.example.seckill.auth.service;

import com.example.seckill.auth.dto.Exposer;
import com.example.seckill.auth.dto.SeckillExecution;
import com.example.seckill.auth.entity.Seckill;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.seckill.auth.exception.RepeatKillException;
import com.example.seckill.auth.exception.SeckillCloseException;
import com.example.seckill.auth.exception.SeckillException;

import java.sql.Timestamp;

/**
 * <p>
 * 秒杀库存表 服务类
 * </p>
 *
 * @author hl
 * @since 2020-06-11
 */
public interface SeckillService extends IService<Seckill> {

    /**
     * 减库存
     * @param seckillId
     * @param killTime
     * @return
     */
    int reduceNumber(long seckillId, Timestamp killTime);

    /**
     * 秒杀开启时输出秒杀接口地址，否则输出系统时间和开启秒杀时间
     * @param seckillId
     */
    Exposer exportSeckillUrl(Long seckillId);

    /**
     * 执行秒杀操作
     * @param seckillId
     * @param userPhone
     * @param md5
     * @return
     */
    SeckillExecution executeSeckill(Long seckillId, Long userPhone, String md5) throws SeckillException, RepeatKillException, SeckillCloseException;

    /**
     * 执行秒杀操作by 存储过程
     * @param seckillId
     * @param userPhone
     * @param md5
     * @return
     */
    SeckillExecution executeSeckillProcedure(Long seckillId, Long userPhone, String md5);
}
